package copyengine.scenes
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	
	import org.puremvc.as3.interfaces.IFacade;

	public class SceneBasic implements IScene
	{
		protected var sceneMediator:SceneBasicMediator;

		private var sceneContainer:DisplayObjectContainer;

		private var facade:IFacade;

		private var sceneMediatorName:String;

		public function SceneBasic()
		{
			sceneContainer = new Sprite();
		}

		public final function setFacade(_facade:IFacade):void
		{
			facade = _facade;
		}

		/**
		 * call when start to initialize current scene, first child class need to override doInitialze() function to init scene ,
		 * then will pass the scene to SceneMediator , SceneMediator will download the data from database and initialze the scene.
		 * after that it will call SceneManger.scenenInitialzeComplate() function.
		 */
		public final function initialize():void
		{
			initSceneMediator();
			doInitialize();
			facade.registerMediator(sceneMediator);
		}

		/**
		 *这个函数会在从服务器取得完数据后调用
		 * 预初始化->从服务器取数据->回调Manger完成预初始化
		 * ->addToLayer->调用此函数
		 */
		public final function onInitializeFinish():void
		{
			sceneMediator.initializeMangerWithData();
			doInitializeFinish();
		}

		protected function doInitializeFinish():void
		{
		}

		protected function doInitialize():void
		{
		}

		public function setParameter(_arg:Object):void
		{
		}

		/**
		 */
		public final function dispose():void
		{
			doDispose();
			facade.removeMediator(sceneMediator.getMediatorName());
		}

		/**
		 * override this function to dispose current scrren property
		 */
		protected function doDispose():void
		{
		}

		/**
		 * if current scrren need to tick child objects then override this function.
		 */
		public function tick():void
		{
		}

		public final function get container():DisplayObjectContainer
		{
			return sceneContainer;
		}

		/**
		 * each scene will need an mediator to handle the initialze part(UI,Data).
		 * and it's communion portal , scene will receive and send notification to other system.
		 */
		private function initSceneMediator():void
		{
			var mediatorClass:Class = getSceneMediatorClass();
			sceneMediator = new mediatorClass(this);
		}

		protected function getSceneMediatorClass():Class
		{
			return SceneBasicMediator;
		}

	}
}
